package com.androidexplosion.takeitback.gui;

import java.text.SimpleDateFormat;
import java.util.List;

import android.content.Context;
import java.sql.Date;

import com.androidexplosion.takeitback.R;
import com.androidexplosion.takeitback.entity.Remind;

import android.view.*;
import android.widget.*;

public class RemindArray extends ArrayAdapter<Remind> {

	int resource;

	public RemindArray(Context _context, int _resource, List<Remind> _items) {
		super(_context, _resource, _items);
		resource = _resource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		RelativeLayout remindView;

		Remind remind = getItem(position);

		String object = remind.getRemindObject();
		Date createdDate = remind.getDate();
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy");
		String dateString = sdf.format(createdDate);

		if (convertView == null) {
			remindView = new RelativeLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
					inflater);
			vi.inflate(resource, remindView, true);
		} else {
			remindView = (RelativeLayout) convertView;
		}

		TextView dateView = (TextView) remindView.findViewById(R.id.rowDate);
		TextView taskView = (TextView) remindView.findViewById(R.id.row);

		dateView.setText(dateString);
		taskView.setText(object);

		return remindView;
	}
}